<%@ page import="com.tlb.ejb.*,com.tlb.dto.*,com.tlb.web.*,java.util.*,java.net.URLEncoder" %>

<%

Poster p = new PosterDAO().getPoster(request.getParameter("userName"), request.getParameter("password"));

String threadId = request.getParameter("threadId");
String postId = request.getParameter("postId");
String treeId = request.getParameter("treeId");
String x = request.getParameter("x");
String action = request.getParameter("action");


if(x == null || x.trim().equals(""))
    x = "";

if(p != null) {
    
    String uuid = new AuthManager().logUserIn(p.getPosterId());
    Cookie c = new Cookie(AuthManager.AUTH_COOKIE_NAME, uuid);
    c.setMaxAge(60*60*24*365);
    response.addCookie(c);

    System.out.println("logged in user: " + p.getUserName());
    
    if(action != null && action.equals("reply") && postId != null && threadId != null)
        //request.getRequestDispatcher("/replyStart.jsp?threadId=" + threadId + "&postId=" + postId + "&treeId=" + treeId + "&x=" + x).forward(request, response);
    	request.getRequestDispatcher("jump.jsp?jumpToPage=" + URLEncoder.encode("replyStart.jsp?threadId=" + threadId + "&postId=" + postId + "&treeId=" + treeId + "&x=" + x, "UTF-8")).forward(request, response);    
    //else if(action != null && action.equals("edit") && postId != null && threadId != null)
    //    request.getRequestDispatcher("jump.jsp?jumpToPage=" + URLEncoder.encode("editStart.jsp?threadId=" + threadId + "&postId=" + postId + "&x=" + x, "UTF-8")).forward(request, response);
    else if(action != null && action.equals("new"))
        request.getRequestDispatcher("jump.jsp?jumpToPage=" + URLEncoder.encode("newThread.jsp","UTF-8")).forward(request, response);
    else
        request.getRequestDispatcher("jump.jsp?jumpToPage=" + URLEncoder.encode("index.jsp","UTF-8")).forward(request, response);
} else {
    System.out.println("Error logging in user: " + request.getParameter("userName"));
    request.setAttribute("loginError", "true");    
    request.getRequestDispatcher("/login.jsp").forward(request, response); 
}


%>
